package cn.bdqn.common.adivce;

import cn.bdqn.common.exception.LyException;
import cn.bdqn.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/***
 *  获取异常信息并且返回
 *  定义人:组长
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e){
        return ResponseEntity.status(e.getExcptionEnum().getCode())
                .body(new ExceptionResult(e.getExcptionEnum()));
    }
}
